package cn.com.nes.site.entity.em.crm.opportunity;

import cn.com.nes.common.exception.NoSuchEnumException;
import cn.com.nes.site.entity.em.IEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 商机分类 枚举
 *  值域对应 t_param 表 param_type=333
 */
@Slf4j
public enum OpportunityClassificationEnum implements IEnum<String> {

    // 客户性质
    RETAIL("01","零售项目"),
    DEALER("02","经销商项目"),
    MANUFACTURE("03","设备厂家项目"),
    GOVERNMENT_PUBLIC("04","政府公共项目"),
    GOVERNMENT_PRIVATE("05","政府自用项目"),
    PUBLIC_INSTITUTIONS("06","公共机构项目"),
    ENTERPRISE("07","企业项目"),
    END_USRE("08", "政府-终端客户项目"),
    OTHER("999","其他"),

    COMMON("1000", "通用查询的类型"),
    ;

    OpportunityClassificationEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }

    private String key;

    private String value;

    @Override
    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }

    public static OpportunityClassificationEnum getEnum(String key) {
        Map<String, OpportunityClassificationEnum> map = new HashMap<>();
        for (OpportunityClassificationEnum opportunityClassificationEnum : values()) {
            map.put(opportunityClassificationEnum.getKey(), opportunityClassificationEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的商机分类");
        }
        return map.get(String.valueOf(key));
    }

    public static String enumConvertKeyToValue(String key) {
        String val = "";
        try {
            val = getEnum(key).getValue();
        } catch (NoSuchEnumException e) {
            log.warn("{}, convert key to value error, key:[{}], cause:[{}]", e.getStackTrace()[0].getFileName(), key, e.getMessage());
        }
        return val;
    }

}
